#include <cstdio>
#include <queue>

using namespace std;

int main( )
{
    int n, k, t;
    char s[ 2 ];
    priority_queue<int, vector<int>, greater<int> > q;
    while ( scanf("%d%d", &n, &k) != EOF )
    {
        while ( !q.empty( ) )
            q.pop( );
        while ( n-- )
        {
            scanf("%s", s);
            if ( s[ 0 ] == 'Q' )
                printf("%d\n", q.top( ));
            else
            {
                scanf("%d", &t);
                if ( q.size( ) < k )
                    q.push( t );
                else
                    if ( q.top( ) < t )
                    {
                        q.pop( );
                        q.push( t );
                    }
            }
        }
    }
    return 0;
}
